package leetcode.code0762;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	static boolean[] isPrime;
	static {
		isPrime = new boolean[33];
		isPrime[2] = true;
		for (int i = 3; i < 33; i++) {
			if (i % 2 == 0) {
				continue;
			}
			boolean ans = true;
			for (int k = 3; k * k <= i; k += 2) {
				if (i % k == 0 || k * k == i) {
					ans = false;
					break;
				}
			}
			isPrime[i] = ans;
		}
	}

	public int countPrimeSetBits(int left, int right) {
		int ans = 0;
		for (int i = left; i <= right; i++) {
			int num = i;
			int cnt = 0;
			while (num > 0) {
				cnt += (num & 1) == 1 ? 1 : 0;
				num >>= 1;
			}
			ans += isPrime[cnt] ? 1 : 0;
		}
		return ans;
	}

	@Override
	public void debug4() {
		HelpDebug.compare(4, this.countPrimeSetBits(6, 10));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
